// Copyright 2008 Senary
// See credits.txt for details.

// This file is part of Omega VII.

// Omega VII is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Omega VII is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Omega VII.  If not, see <http://www.gnu.org/licenses/>.

#include <set>

#include "GameManager.h"
#include "Player.h"
#include "SpaceObject.h"

using namespace std;

Player::Player(void)
{
	_income = 200000; //default gold
	_upkeep = 0;
}

Player::~Player(void)
{
}

void Player::addPlanet(Planet* p)
{
	_planets.insert(p);
}

void Player::addSpaceship(Spaceship* s)
{
	_spaceships.insert(s);
}

void Player::removePlanet(Planet* p)
{
	_planets.erase(p);
}

void Player::removeSpaceship(Spaceship* s)
{
	_spaceships.erase(s);
}

set<Planet*> const& Player::getPlanets() const
{
	return _planets;
}

set<Spaceship*> const& Player::getSpaceships() const
{
	return _spaceships;
}

int Player::getIncome(){

	return _income;
}



void Player::setIncome(int income){
	_income = income;
	

}

bool Player::isEnemy(SpaceObject * so) const
{
	// TODO: alliances?
	return (so->getOwner() != this && so->getOwner());
}

void Player::update(float timestep, float totalTime) {

	float upkeep = 0;
	for (set<Spaceship*>::iterator i = _spaceships.begin();
		 i != _spaceships.end(); ++i) {
			 upkeep+= (*i)->upkeep();
	}
	_upkeep = upkeep;

}


string const& Player::getName() const{
	return _name;
}



void Player::setName(string const& name)
{
	_name = name;
}

void Player::setIsHumanPlayer(bool value)
{
	isHumanPlayer = value;
}

bool Player::getIsHumanPlayer()
{
	return isHumanPlayer;
}

float Player::getUpkeep()
{
	return _upkeep;
}

void Player::setUpkeep(float upkeep)
{
	_upkeep = upkeep;
}
